package com.home.cop.employee.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.home.cop.employee.mapper.SysUserMapper;
import com.home.cop.employee.model.SysUser;
import com.home.cop.employee.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class SysUserServiceImpl implements SysUserService {

    @Autowired
    private SysUserMapper userMapper;

    @Override
    public SysUser getUser(String account, String pass) {
        return userMapper.getUser(account,pass);
    }

    @Override
    public PageInfo<SysUser> list(Map<String, Object> params, int pageSize, int pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<>(userMapper.list(params));
    }

    @Override
    public List<SysUser> getUserByPhone(String phone) {
        return userMapper.getUserByPhone(phone);
    }

    @Override
    public List<SysUser> getInstUsers(Integer instId) {
        return userMapper.getInstUsers(instId);
    }

    @Transactional
    @Override
    public void deleteSysUser(String account) {
        userMapper.deleteSysUser(account);
    }

    @Transactional
    @Override
    public void insert(SysUser user) {
        userMapper.insert(user);
    }

    @Transactional
    @Override
    public void updateUserInfo(SysUser user) {
        userMapper.updateUserInfo(user);
    }

    @Transactional
    @Override
    public void updateStatus(String account, Integer status) {
        userMapper.updateStatus(account,status);
    }

    @Override
    public Integer countUserByRoleId(Integer roleId) {
        return userMapper.countUserByRoleId(roleId);
    }

    @Override
    public void updateUserPass(String account,String pass) {
        userMapper.updateUserPass(account,pass);
    }
}
